package modelLag;
import java.util.ArrayList;

/**
 * Write a description of class ForestContainer here.
 * 
 * @author (Anders Mortensen) 
 * @version (1.0 03-11-14)
 */
public class DVDContainer
{
    // instance variables
    private static DVDContainer dvdCon;
    private ArrayList<DVD> dvdList;

    /**
     * Constructor for objects of class DVDContainer
     */
    private DVDContainer() {
        dvdList = new ArrayList<DVD>(); 
    }

    /**
     * An example of a method - replace this comment with your own
     * 
     * @param  y   a sample parameter for a method
     * @return     the sum of x and y 
     */
    public static DVDContainer getInstance() {
        if(dvdCon ==null) {
            dvdCon = new DVDContainer();
        }
        return dvdCon;
    }
    
    public void addDVD(DVD dvd) {
        dvdList.add(dvd);
    }
    
    public DVD findDVD(int barcode) {
        int i=0;
        boolean found = false;
        DVD dvd = null;
        while(i<dvdList.size() && !found) {
            DVD getDvd = dvdList.get(i);
            int dvdBarcode = getDvd.getBarcode();
            if (dvdBarcode == barcode) {
                found = true;
                dvd = dvdList.get(i);
                
            }
            else {
                i++;
            }
        }
        return dvd;
    }
    
    public void deleteDVD(String title) {
        int i=0;
        boolean found = false;
        while(i<dvdList.size() && !found) {
            DVD dvd = dvdList.get(i);
            String dvdTitle = dvd.getTitle();
            if (dvdTitle.equals(title)) {
                found = true;
                
            }
            else {
                i++;
            }
        }
        if (found) {
            dvdList.remove(i);
        }
    }
    
    public void prinDvdList() {
        System.out.println("Title:            Barcode:");
        for (DVD dvd : dvdList) {
            System.out.println(dvd.getTitle()+"            "+dvd.getBarcode()+"\n");
        }
    }
            
    
    /*public void updateDVD(int oldBarcode, DVD newDvd)
    {
       int i=0;
       boolean found = false;
        while(i<dvdList.size() && !found){
            DVD dvd = dvdList.get(i);
            int barcode = dvd.getBarcode();
            if (barcode == oldBarcode){
                found = true;
                
            }
            else{
                i++;
            }
       }
       if(found)
       {
           dvdList.set(i, newDvd);
       }
    }*/
}
